package main

import (
	"fmt"
	"unsafe"
)

/*
*
数组与切片
看到:220页
*/
func main() {
	fmt.Println("Hello, World!name:")

	var arr [5]float64
	arr[0] = 10.2
	arr[1] = 2.1
	arr[2] = 8.2
	arr[3] = 3.7
	arr[4] = 9.4

	fmt.Printf("arr:%v,类型为:%T,字节大小:%v\n", arr, arr, unsafe.Sizeof(arr))
	/* 计算总数 */
	var total float64 = 0.0
	for i := 0; i < len(arr); i++ {
		total += arr[i]
	}
	fmt.Printf("总数为:%v,平均值为:%v\n", total, total/float64(len(arr)))
	fmt.Printf("内存的地址值为:%p,第一个数:%p,第二个数:%p,第三个数:%p\n", &arr, &arr[0], &arr[1], &arr[2])

	fmt.Println("==数组的初始化==")
	var arr1 [3]int = [3]int{1, 2, 3}
	fmt.Printf("arr1:%v,类型为:%T,字节大小:%v\n", arr1, arr1, unsafe.Sizeof(arr1))

	var arr2 = [...]int{1, 2, 3}
	fmt.Printf("arr2:%v,类型为:%T,字节大小:%v\n", arr2, arr2, unsafe.Sizeof(arr2))

	var arr3 = [3]int{1, 2, 3}
	fmt.Printf("arr3:%v,类型为:%T,字节大小:%v\n", arr3, arr3, unsafe.Sizeof(arr3))

	var arr4 = [...]int{1: 1, 3: 2, 0: 3}
	fmt.Printf("arr4:%v,类型为:%T,字节大小:%v\n", arr4, arr4, unsafe.Sizeof(arr4))

	fmt.Println("==数组循环==")
	for i := 0; i < len(arr4); i++ {
		fmt.Printf("arr4[%d]=%v\n", i, arr4[i])
	}

	for index, value := range arr4 {
		fmt.Printf("index:%d,value:%v\n", index, value)
	}
}
